/**
 * 菜单控制器
 * 作者：GodMainCode
 * 创建时间：2024-01-17
 * 修改时间：2024-01-17
 * 修改人：GodMainCode
 */

import { Controller, Get, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { MenuService } from './menu.service';
import { PermissionService } from './permission.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { RequirePermissions } from '../auth/decorators/permissions.decorator';
import { MenuResponseDto } from './dto/menu-response.dto';

@ApiTags('菜单管理')
@UseGuards(JwtAuthGuard)
@Controller('menu')
export class MenuController {
  constructor(
    private readonly menuService: MenuService,
    private readonly permissionService: PermissionService,
  ) {}

  @Get()
  @RequirePermissions('menu:read')
  @ApiOperation({ summary: '获取菜单树' })
  @ApiResponse({
    status: 200,
    description: '获取菜单树成功',
    type: [MenuResponseDto],
  })
  async getMenuTree(): Promise<MenuResponseDto[]> {
    const permissions = await this.permissionService.findAll();
    return this.menuService.transformToMenuTree(permissions);
  }
} 